home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / sys / amiga / programmer / 1972 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. Path: sable.ox.ac.uk!sjoh0358
  2. From: sjoh0358@sable.ox.ac.uk (Ian Parkinson)
  3. Newsgroups: comp.sys.amiga.programmer
  4. Subject: Re: More linked list nonsense
  5. Date: 25 Jan 1996 16:50:39 GMT
  6. Organization: Oxford University, England
  7. Message-ID: <4e8ccv$7ei@news.ox.ac.uk>
  8. References: <4e5nih$iib@news.sdd.hp.com>
  9. NNTP-Posting-Host: sable.ox.ac.uk
  10.  
  11. In article <4e5nih$iib@news.sdd.hp.com>,
  12. Jeff Grimmett  <jgrimm@sdd.hp.com> wrote:
  13. >
  14. >Howdy,
  15. >
  16. >It just occurred to me last night, as I pored over steaming code, that 
  17. >the function Remove() (used to remove nodes from linked lists) might 
  18. >POSSIBLY not be freeing the memory allocated to the node it is removing. 
  19. >Does anyone have some insight on this?  It's difficult to deallocate a 
  20. >node once it's not part of the list, but it's pretty STUPID to free it 
  21. >BEFORE. :-)
  22.  
  23. I don't have the docs handy, and I haven't done anything with linked lists
  24. for a while, but as far as I recall:
  25.  
  26. Remove() simply fixes the pointers on adjacent nodes to effectively push the
  27. chosen node out of the list. It still remains in memory and so has to be freed
  28. explicitly by the program. At least, that's the way I did it!
  29.  
  30. In general, if you explicitly allocate the memory with a MemAlloc() or
  31. whatever, then it is also up to you to deallocate it. This goes for any part of
  32. the OS, not just linked lists.
  33.  
  34. To deallocate after Remove(), just store the address of the node somewhere
  35. before you Remove() it. Then deallocate using this address.
  36.  
  37. Ian
  38.  
  39.  
  40.